package hlhj.fhp.checkpoint.module

import android.content.Context
import com.example.mymvp.log
import com.example.mymvp.mvp.BaseModule
import com.lzy.okgo.model.Response
import hlhj.fhp.checkpoint.http.Apis
import hlhj.fhp.checkpoint.http.CustomAction
import hlhj.fhp.checkpoint.http.LoadingAction
import hlhj.fhp.checkpoint.javaBean.LoginBean
import hlhj.fhp.checkpoint.javaBean.MyBaseBean
import hlhj.fhp.checkpoint.javaBean.SendSMSBean

/**
 * Created by Never Fear   on 2018\11\13 0013.
Never More....
 */
class LoginModule :BaseModule {
    var listener:LoginListener?=null
    /**
     * 登录
     */
    fun login(phone:String,code:String,recommend:String,imei:String,c:Context){
        Apis.login(phone, code, recommend, imei)
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :CustomAction<Response<LoginBean>>(c){
                                override fun httpSuccess(t: Response<LoginBean>) {
                                    listener?.loginResp(t.body())
                                }
                            })
                }
    }

    /**
     * 验证码
     */
    fun sendSms(phone:String,c:Context){
        Apis.sendSms(phone)
                ?.doOnSubscribe(LoadingAction(c))
                ?.subscribe(object :CustomAction<Response<SendSMSBean>>(c){
                    override fun httpSuccess(t: Response<SendSMSBean>) {
                        log("okgo","访问完成回调了嘛？")
                        listener?.sendSmsResp(t.body())
                    }
                })
    }
    interface LoginListener{
        fun loginResp(loginBean: LoginBean)
        fun sendSmsResp(myBaseBean: SendSMSBean)
    }
}